home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / ace23.lha / MAIN.lha / include / hex.h < prev    next >
C/C++ Source or Header  |  1994-10-22  |  644b  |  42 lines

  1. '..hexadecimal functions.
  2.  
  3. #include <stddef.h>
  4.  
  5. SUB hexdigit(x$)
  6.   if (x$>="A" and x$<="F") or (x$>="0" and x$<="9") then 
  7.     hexdigit=true 
  8.   else 
  9.     hexdigit=false
  10.   end if
  11. END SUB
  12.  
  13. SUB hex_to_dec&(x$)
  14. longint n,i
  15. longint length
  16. longint legal.digit
  17.  
  18.   '..converts a hex string 
  19.   '..to a long integer.
  20.  
  21.   i=1
  22.   n=0
  23.   length=len(x$)
  24.  
  25.   repeat
  26.     s$=ucase$(mid$(x$,i,1))
  27.     legal.digit=hexdigit(s$)
  28.  
  29.     if i<=length and legal.digit then 
  30.       n=n*16
  31.       if s$>="A" then 
  32.         n=n+asc(s$)-asc("A")+10
  33.       else
  34.     n=n+asc(s$)-asc("0")
  35.       end if
  36.     end if    
  37.     ++i
  38.   until i>length or not legal.digit
  39.  
  40.   hex_to_dec& = n
  41. END SUB
  42.